package com.empty_pro.newone;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.ListActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class MYListActivity extends ListActivity {
    Handler handler;
    private static final String TAG = "ML";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mylist);

        //
        GridView gridView = findViewById(R.id.gridview);
        //列表

        List<String> list1 = new ArrayList<String>();
        for (int i = 1; i < 100; i++) {
            list1.add("item" + i);
        }
        //String[] list_data={"one","two","there","four"};
        ListAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, list1);

        gridView.setAdapter(adapter);
        gridView.setEmptyView(findViewById(R.id.nodata));



        /*
        ArrayList<HashMap<String, String>> listItems = new ArrayList<HashMap<String, String>>();

        for(int i=0;i<10;i++){
            HashMap<String,String> map=new HashMap<String,String>();
            map.put("ItemTitle","rate "+i);
            map.put("TtemDetail","detail "+i);
            listItems.add(map);
        }


 */
        /*
        SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItems, R.layout.list_item, new String[]{"ItemTitle", "ItemDetail"}, new int[]
                {R.id.name, R.id.rate});
        setListAdapter(listItemAdapter);
        */
        /*
        MyAdapter myAdapter=new MyAdapter(this,R.layout.list_item,listItems);
        setListAdapter(myAdapter);


         */
        //

/*
        handler = new Handler(Looper.myLooper()) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 5) {

                    List<String> list2 = (List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(MYListActivity.this,
                            android.R.layout.simple_list_item_1, list2);
                    setListAdapter(adapter);


                    ArrayList<HashMap<String, String>> listItems = (ArrayList<HashMap<String, String>>) msg.obj;
                    MyAdapter myAdapter = new MyAdapter(MYListActivity.this, R.layout.list_item, listItems);
                    setListAdapter(myAdapter);





                }
                super.handleMessage(msg);
            }

        };

 */


        /*

        MyNetWork1 work1=new MyNetWork1();
        work1.setHandler(handler);
        Thread t = new Thread(work1);
        t.start();

         */


        //getListView().setOnClickListener((View.OnClickListener) this);

    }





    /*
    @Override
    public void run() {
            /*
            //URL url = null;
            //url = new URL("www.usd-cny.com/bankofchina.htm");
            //https://www.boc.cn/sourcedb/whpj/
            // 解析数据
            String url = "https://www.boc.cn/sourcedb/whpj/";
            List<String> list = new ArrayList<>();
            try {
                Document doc = Jsoup.connect(url).get();

                String html= doc.html();
                //Log.i(TAG, "run: 解析结果日志输出"+html)

                Element table = doc.getElementsByTag("table").get(1);
                Elements tds = table.getElementsByTag("td");

                for (int i = 0; i < tds.size(); i += 8) {
                    Element td1 = tds.get(i);
                    Element td2 = tds.get(i + 5);
                    list.add(td1.text() + "==>" + td2.text());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            //将参数传回主线程
            Message msg = handler.obtainMessage(5, list);
            handler.sendMessage(msg);
            //


        }
        */


}




    /*
    @Override
    public void run() {
        //URL url = null;
        //url = new URL("www.usd-cny.com/bankofchina.htm");
        // 解析数据
        String url = "https://www.usd-cny.com/bankofchina.htm";
        List<String> list=new ArrayList<>();
        try {
            Document doc = Jsoup.connect(url).get();

            Element table = doc.getElementsByTag("table").first();
            Elements tds = table.getElementsByTag("td");

            for (int i = 0; i < tds.size(); i += 6) {
                Element td1 = tds.get(i);
                Element td2 = tds.get(i + 5);
                list.add(td1.text()+"==>"+td2.text());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        //将参数传回主线程
        Message msg=handler.obtainMessage(5,list);
        handler.sendMessage(msg);
        //
    }

}

     */






